from django.shortcuts import render
from rest_framework import viewsets
from rest_framework.generics import ListAPIView

from home.serializers import HealthCategorySerializer,HealthDirectionSerializer,LifeCategorySerializer,LifeDirectionSerializer
from home.models import HealthCategory,HealthDirection,LifeCategory,LifeDirection
# Create your views here.
class HealthDirectionViewSet(ListAPIView):
    queryset = HealthDirection.objects.all()
    serializer_class = HealthDirectionSerializer
class HealthCategoryViewSet(ListAPIView):

    serializer_class = HealthCategorySerializer
    def get_queryset(self):
        print(self.kwargs)
        direction_id = int(self.kwargs.get('directionID',1))
        print(direction_id)
        query_set = HealthCategory.objects.filter(is_show=True).order_by("id")
        print(query_set)
        if direction_id >=1:
            query_set =query_set.filter(direction_id= direction_id)
            print("---------")
            print(query_set)
            return query_set

class LifeDirectionViewSet(ListAPIView):
    queryset = LifeDirection.objects.all()
    serializer_class = LifeDirectionSerializer
class LifeCategoryViewSet(ListAPIView):
    serializer_class = LifeCategorySerializer
    def get_queryset(self):
        print("------")
        print(self.kwargs)
        direction_id = int(self.kwargs.get('directionID',1))
        query_set = LifeCategory.objects.filter(is_show = True).order_by("id")
        if direction_id >=1:
            query_set =query_set.filter(direction= direction_id)
            return query_set